<template>
  <!-- 微信记录查询 -->
  <section class="page app-record-query">
    <data-form :model="searchModel" @onSearch="refreshData" :rules="rules" :page="pageService">
      <template slot="inputs">
        <el-form-item label="账户号" prop="caseNumber">
          <el-input v-model="searchModel.caseNumber"></el-input>
        </el-form-item>
        <el-form-item label="客户号" prop="personalNo">
          <el-input v-model.trim="searchModel.personalNo"></el-input>
        </el-form-item>
        <el-form-item label="客户姓名" prop="personalName">
          <el-input v-model.trim="searchModel.personalName" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="证件号" prop="idCard">
          <el-input v-model.trim="searchModel.idCard" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobileNo">
          <el-input v-model.trim="searchModel.mobileNo" maxlength="11"></el-input>
        </el-form-item>
        <el-form-item label="发送内容" prop="content">
          <el-input v-model.trim="searchModel.content" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="发送人" prop="createName">
          <el-input v-model.trim="searchModel.createName" maxlength="20"></el-input>
        </el-form-item>
        <el-form-item label="发送时间" prop="createdTime">
          <el-date-picker type="daterange" :editable="false" v-model="searchModel.createdTime" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions" clearable>
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发送状态" prop="sendResult">
          <el-select v-model="searchModel.sendResult" placeholder="请选择" clearable>
            <el-option v-for="{ index, name, code } in $dict.getDictData('SendResult')" :key="index" :label="name" :value="code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属队列" prop="queueCode">
          <el-input v-model.trim="searchModel.queueCode"></el-input>
        </el-form-item>
      </template>
    </data-form>

    <data-box :data="dataSet" @onPageChange="refreshData" :page="pageService">
      <template slot="columns">
        <!--数据列区域-->
        <el-table-column prop="caseNumber" label="账户号" :min-width="$helper.getColumnWidth(6)">
          <template slot-scope="scope">
            <el-button type="text" @click="openExecutionPage(scope.row)">{{
              scope.row.caseNumber
            }}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="relation" label="与客户关系" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip :formatter="row => $filter.dictConvert(row.relation, 'Relationship')"></el-table-column>
        <el-table-column prop="personalName" label="客户姓名" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mobileNo" label="手机号" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="idCard" label="证件号" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="queueCode" label="所属队列" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="templateName" label="模板名称" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="appAccount" label="APP账号" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="content" label="发送内容" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="agentCode" label="经办代号" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="createName" label="操作员代号" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="createdTime" label="发送时间" :min-width="$helper.getColumnWidth(3)" :formatter="row => $filter.dateTimeFormat(row.createdTime)" show-overflow-tooltip></el-table-column>
        <el-table-column prop="sendResult" label="发送状态" :min-width="$helper.getColumnWidth(3)" show-overflow-tooltip :formatter="row => $filter.dictConvert(row.sendResult, 'SendResult')"></el-table-column>
      </template>
    </data-box>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Layout, Dependencies } from "~/core/decorator";
import { PageService } from "~/utils/page.service";
import { SortService } from "~/utils/sort.service";
import NumberRange from "~/components/common/number-range.vue";
import { SynthesizeQueryService } from "~/services/domain-service/synthesize-query.service";
import { namespace, Getter, Mutation, State } from "vuex-class";
import { MENU_CHANNEL } from "../../config/enum.config";

@Layout("workspace")
@Component({
  components: {
    NumberRange
  }
})
export default class AppRecordQuery extends Vue {
  @Dependencies(PageService) private pageService: PageService;
  @Dependencies(SortService) private sortService: SortService;
  @Dependencies(SynthesizeQueryService)
  private synthesizeQueryService: SynthesizeQueryService;
  private searchModel: any = {
    caseNumber: "",
    personalName: "",
    mobileNo: "",
    personalNo: "",
    idCard: "",
    content: "",
    queueCode: "",
    createTime: [],
    sendResult: "",
    createName: ""
  };
  private dataSet: any[] = [];

  private pickerOptions = {
    disabledDate (time) {
      return time.getTime() > Date.now();
    },
  }

  // 表单验证规则
  private rules = {
    mobileNo: [{ validator: this.$validator.phoneNumber, trigger: "change" }],
    idCard: [{ validator: this.$validator.idcardUscc, trigger: "change" }]
  };

  private mounted () {
    this.refreshData();
  }

  private refreshData () {
    const params = { ...this.searchModel };
    params.createdTimeMax = this.$filter.dateRanageFormat(
      this.searchModel.createdTime
    ).end;
    params.createdTimeMin = this.$filter.dateRanageFormat(
      this.searchModel.createdTime
    ).start;
    delete params.createdTime;
    this.synthesizeQueryService
      .getAllAppRecord(params, this.pageService)
      .subscribe(data => (this.dataSet = data));
  }
  /**
   * 进入查看执行页
   */
  private openExecutionPage (row) {
    this.$router.openCaseDetail(row.id, {
      menuChannel: MENU_CHANNEL.App_record_query,
      hiddenCaseList: true,
      hiddenAction: true,
      hiddenRemark: true
    });
  }
}
</script>
<style lang="less">
.case-record-query {
  .el-dialog__footer {
    text-align: center !important;
  }
}
</style>
